package com.niit.controller.hive;

import java.sql.*;

public class YouTube5 {
    private static String driverClass = "org.apache.hive.jdbc.HiveDriver";
    public static void main(String[] args) throws SQLException {

        try {
            Class.forName(driverClass);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        Connection connection = DriverManager.getConnection("jdbc:hive2://hadoop:10000/default","root","niit1234");
        Statement statement = connection.createStatement();

        String table_name ="youtube";
        String query1 = "Select category,avg(no_of_comments) as acom,max(no_of_views) as maxview,min(no_of_rating) as minrate from "+table_name+" group by category";

        ResultSet result = statement.executeQuery(query1);
        while(result.next()) {
            String category = result.getString(1);
            String acom = result.getString(2);
            Integer maxview = result.getInt(3);
            Integer minrate = result.getInt(4);
        }
        result.close();
        statement.close();
        connection.close();

    }
}